package 剑指offer.Month7_07.day18;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;

public class 字符流中第一个不重复的字符 {
    HashMap<Character,Integer> hashMap = new HashMap<>();
    Queue<Character> q = new LinkedList<>();//用来存放字符
    public void Insert(char ch)
    {
        if(!hashMap.containsKey(ch)) q.offer(ch);
        hashMap.put(ch,hashMap.getOrDefault(ch,0) + 1);
    }
    //return the first appearence once char in current stringstream
    public char FirstAppearingOnce()
    {
        while(!q.isEmpty()){
            if(hashMap.get(q.peek()) != 1){
                q.poll();
            }else{
                return q.peek();
            }
        }
        return '#';
    }
}
